<template>
    <div>
        <h1>显示</h1>
        房号<input type="text" v-model="info.userfh">
        <input type="button" value="查询" @click="getlist">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房间名称</td>
                    <td>房号</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="itme in data.list":key="itme.Id">
                    <td>{{ itme.Name }}</td>
                    <td>{{ itme.Userfh }}</td>
                    <td>{{ itme.State?"上架":"下架" }}</td>
                    <td><input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
const router=useRouter();
let info:any=reactive({

  userfh: '',

})
let data:any=reactive({
    list:[],
})
onMounted(()=>{
    getlist();
})
const getlist=()=>{
    axios({
        url:'/api/User/GetAll',
        method:'get',
        params:info
    })
    .then((res)=>{
        console.log(res);
       data.list=res.data;
    })
    .catch((err)=>{
        console.log(err);
        
    })
}


const del=(id:any)=>{
    axios({
        url:'/api/User/DEL',
        method:'delete',
        params:{
            id:id
        }
    })
    .then((res)=>{
        console.log(res);
        
    if(res.data>0)
    {
        alert("删除成功")
        getlist();
        return;
    }
    else{
        alert("删除失败")
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}



const xg=(id:any)=>{
    router.push({
        path:'/fxxg',
        query:{
            id:id
        }
    })
}
</script>

<style scoped>

</style>